package com.uidt.project.ptsj.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.uidt.framework.aspectj.lang.annotation.Log;
import com.uidt.framework.aspectj.lang.enums.BusinessType;
import com.uidt.project.ptsj.domain.PlaceInfo;
import com.uidt.project.ptsj.service.IPlaceInfoService;
import com.uidt.framework.web.controller.BaseController;
import com.uidt.framework.web.domain.AjaxResult;
import com.uidt.common.utils.poi.ExcelUtil;
import com.uidt.framework.web.page.TableDataInfo;

/**
 * 场所信息Controller
 * 
 * @author uidt
 * @date 2024-08-15
 */
@RestController
@RequestMapping("/ptsj/place")
public class PlaceInfoController extends BaseController
{
    @Autowired
    private IPlaceInfoService placeInfoService;

    /**
     * 查询单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:list')")
    @GetMapping("/list")
    public TableDataInfo list(PlaceInfo ptsjPlaceInfo)
    {
        startPage();
        List<PlaceInfo> list = placeInfoService.selectPlaceInfoList(ptsjPlaceInfo);
        return getDataTable(list);
    }

    /**
     * 导出单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:export')")
    @Log(title = "单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlaceInfo ptsjPlaceInfo)
    {
        List<PlaceInfo> list = placeInfoService.selectPlaceInfoList(ptsjPlaceInfo);
        ExcelUtil<PlaceInfo> util = new ExcelUtil<PlaceInfo>(PlaceInfo.class);
        util.exportExcel(response, list, "单位信息数据");
    }

    /**
     * 获取单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:query')")
    @GetMapping(value = "/{placeCode}")
    public AjaxResult getInfo(@PathVariable("placeCode") String placeCode)
    {
        return success(placeInfoService.selectPlaceInfoByPlaceCode(placeCode));
    }

    /**
     * 新增单位信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:add')")
    @Log(title = "单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlaceInfo ptsjPlaceInfo)
    {
        return toAjax(placeInfoService.insertPlaceInfo(ptsjPlaceInfo));
    }

    /**
     * 修改单位信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:edit')")
    @Log(title = "单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlaceInfo ptsjPlaceInfo)
    {
        return toAjax(placeInfoService.updatePlaceInfo(ptsjPlaceInfo));
    }

    /**
     * 删除单位信息
     */
    @PreAuthorize("@ss.hasPermi('ptsj:place:remove')")
    @Log(title = "单位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{placeCodes}")
    public AjaxResult remove(@PathVariable String[] placeCodes)
    {
        return toAjax(placeInfoService.deletePlaceInfoByPlaceCodes(placeCodes));
    }

    /**
     * 获取当前场所的积分排名
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:place:remove')")
//    @Log(title = "单位信息", businessType = BusinessType.DELETE)
    @PostMapping("/getPlaceRankByCode")
    public AjaxResult getPlaceRankByCode(@RequestParam("placeCode") String placeCode)
    {
        return success(placeInfoService.getPlaceRankByCode(placeCode));
    }

    /**
     * 获取当前场所的积分排名
     */
//    @PreAuthorize("@ss.hasPermi('ptsj:place:remove')")
//    @Log(title = "单位信息", businessType = BusinessType.DELETE)
    @PostMapping("/getPlaceRankList")
    public TableDataInfo getPlaceRankList(PlaceInfo ptsjPlaceInfo)
    {
        startPage();
        List<PlaceInfo> list = placeInfoService.getPlaceRankList(ptsjPlaceInfo);
        return getDataTable(list);
    }

}
